<html>
<head>
    <title>My simple money calculator on JavaScript</title>
    <style>
        .result { font-weight: bold; }
        #payment { text-decoration: underline; }
    </style>
<body>
    <form name="loandata">
        <table>
            <tr><td><b>Enter data:</b><td></tr>
            <tr>
                <td>1) Razmer ssudy:</td>
                <td><input type="text" name="principal" onchange="calculate();"></td>
            </tr>
            <tr>
                <td>2) Godovoy procent:</td>
                <td><input type="text" name="interest" onchange="calculate();"></td>
            </tr>
            <tr>
                <td>3) Srok ssudy v godah:</td>
                <td><input type="text" name="years" onchange="calculate();"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="Calculate" onclick="calculate();"></td>
            </tr>
            <tr>
                <td><b>Svedeniya o platejah:</b></td>
            </tr>
            <tr>
                <td>4) Ejemesyachniy platej:</td>
                <td>$<span class="result" id="payment"></span></td>
            </tr>
            <tr>
                <td>5) Obshchaya summa platejey:</td>
                <td>$<span class="result" id="total"></span></td>
            </tr>
            <tr>
                <td>6) Obshchaya summa platejey po procentam:</td>
                <td>$<span class="result" id="totalinterest"></span></td>
            </tr>
        </table>
    </form>
    <script language="JavaScript">
        function calculate() {
            var principal = document.loandata.principal.value;
            var interest = document.loandata.interest.value / 100 / 12;
            var payments = document.loandata.years.value * 12;

            var x = Math.pow(1 + interest, payments);
            var monthly = (principal * x * interest) / (x - 1);

            var payment = document.getElementById("payment");
            var total = document.getElementById("total");
            var totalinterest = document.getElementById("totalinterest");

            if (isFinite(monthly)) {
                payment.innerHTML = monthly.toFixed(2);
                total.innerHTML = (monthly * payments).toFixed(2);
                totalinterest.innerHTML = ((monthly * payments) - principal).toFixed(2);
            } else {
                payment.innerHTML = "";
                total.innerHTML = "";
                totalinterest.innerHTML = "";
            }
        }
    </script>
</body>
